var account = document.querySelector('#account');
var password = document.querySelector('#password');
var toMain = function() {
	mui.openWindow({
		"id": 'main.html',
		"url": 'main.html'
	});
};
document.addEventListener('plusready', function() {
	var user = app.getUser();
	if(user) {
		plus.nativeUI.showWaiting('登录中...');
		app.login(user, function(user) {
			plus.nativeUI.closeWaiting();
			if(user) {
				app.setUser(user);
				toMain();
			} else {
				app.removeUser();
			}
		});
	}
});
document.querySelector('#login').addEventListener('tap', function(event) {
	var rsa = new JSEncrypt();
	rsa.setPublicKey(app.publicKey);
	var user = {
		account: rsa.encrypt(account.value),
		password: rsa.encrypt(password.value)
	};
	mui('#login').button('loading');
	app.login(user, function(user) {
		if(user) {
			app.setUser(user);
			toMain();
			mui('#login').button('reset');
		} else {
			app.removeUser();
			plus.nativeUI.alert('帐号或密码错误');
			mui('#login').button('reset');
		}
	});
});